package com.upb.webserver.dao.mapper;

import com.upb.webserver.dao.entity.TbSecurity;
import com.upb.webserver.dao.entity.TbSecurityExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

public interface TbSecurityMapper {

    @Insert({ "insert into tb_security (appid, security, ", "related_key)", "values (#{appid,jdbcType=VARCHAR}, #{security,jdbcType=VARCHAR}, ", "MD5(CONCAT(#{pid,jdbcType=VARCHAR},'##$$##',#{account,jdbcType=VARCHAR})))" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insertByInfos(@Param("pid") String pid, @Param("account") String account, @Param("appid") String appid, @Param("security") String security);

    @Select({ "select", "id, appid, security, related_key", "from tb_security", "where related_key = MD5(CONCAT(#{pid,jdbcType=VARCHAR},'##$$##',#{account,jdbcType=VARCHAR}))" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "appid", property = "appid", jdbcType = JdbcType.VARCHAR), @Result(column = "security", property = "security", jdbcType = JdbcType.VARCHAR), @Result(column = "related_key", property = "relatedKey", jdbcType = JdbcType.VARCHAR) })
    TbSecurity getSecurityByRelatedKey(@Param("pid") String pid, @Param("account") String account);


    @Delete({ "delete from tb_security", "where related_key = MD5(CONCAT(#{pid,jdbcType=VARCHAR},'##$$##',#{account,jdbcType=VARCHAR}))" })
    int deleteByRelatedKey(@Param("pid") String pid, @Param("account") String account);



    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbSecuritySqlProvider.class, method = "countByExample")
    long countByExample(TbSecurityExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @DeleteProvider(type = TbSecuritySqlProvider.class, method = "deleteByExample")
    int deleteByExample(TbSecurityExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @Delete({ "delete from tb_security", "where id = #{id,jdbcType=INTEGER}" })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @Insert({ "insert into tb_security (appid, security, ", "related_key)", "values (#{appid,jdbcType=VARCHAR}, #{security,jdbcType=VARCHAR}, ", "#{relatedKey,jdbcType=VARCHAR})" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(TbSecurity record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @InsertProvider(type = TbSecuritySqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insertSelective(TbSecurity record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbSecuritySqlProvider.class, method = "selectByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "appid", property = "appid", jdbcType = JdbcType.VARCHAR), @Result(column = "security", property = "security", jdbcType = JdbcType.VARCHAR), @Result(column = "related_key", property = "relatedKey", jdbcType = JdbcType.VARCHAR) })
    List<TbSecurity> selectByExample(TbSecurityExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @Select({ "select", "id, appid, security, related_key", "from tb_security", "where id = #{id,jdbcType=INTEGER}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "appid", property = "appid", jdbcType = JdbcType.VARCHAR), @Result(column = "security", property = "security", jdbcType = JdbcType.VARCHAR), @Result(column = "related_key", property = "relatedKey", jdbcType = JdbcType.VARCHAR) })
    TbSecurity selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbSecuritySqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbSecurity record, @Param("example") TbSecurityExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbSecuritySqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") TbSecurity record, @Param("example") TbSecurityExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbSecuritySqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbSecurity record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @Update({ "update tb_security", "set appid = #{appid,jdbcType=VARCHAR},", "security = #{security,jdbcType=VARCHAR},", "related_key = #{relatedKey,jdbcType=VARCHAR}", "where id = #{id,jdbcType=INTEGER}" })
    int updateByPrimaryKey(TbSecurity record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert({ "<script>", "insert into tb_security (appid, ", "security, related_key)", "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.appid,jdbcType=VARCHAR}, ", "#{detail.security,jdbcType=VARCHAR}, #{detail.relatedKey,jdbcType=VARCHAR})</foreach></script>" })
    int batchInsert(List<TbSecurity> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_security
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbSecuritySqlProvider.class, method = "getOneByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "appid", property = "appid", jdbcType = JdbcType.VARCHAR), @Result(column = "security", property = "security", jdbcType = JdbcType.VARCHAR), @Result(column = "related_key", property = "relatedKey", jdbcType = JdbcType.VARCHAR) })
    Optional<TbSecurity> getOneByExample(TbSecurityExample example);
}
